x = int(input())
max_prost = 0
a = x // 1000
b = x % 1000 // 100
d = x % 100 // 10
c = x % 10
if len (str(x)) != 4 or x < 0:
    print(0)
else:
    m = a * 1000 + b * 100 + d * 10 + c
    w = 0
    for i in range(1, m+1):
        if m % i==0:
            w+=1
    if w==2:
        max_prost=max(max_prost, m)
    m2 = a * 100 + b * 10 + d
    w2 = 0
    for i2 in range(1, m2+1):
        if m2 % i2==0:
            w2+=1
    if w2==2:
        max_prost=max(max_prost, m2)
    m3 = b * 100 + d * 10 + c
    w3 = 0
    for i3 in range(1, m3+1):
        if m3 % i3==0:
            w3+=1
    if w3==2:
        max_prost=max(max_prost, m3)
    m4 = a * 10 + b
    w4 = 0
    for i4 in range(1, m4+1):
        if m4 % i4==0:
            w4+=1
    if w4==2:
        max_prost=max(max_prost, m4)
    m5 = b * 10 + d
    w5 = 0
    for i5 in range(1, m5+1):
        if m5 % i5==0:
            w5+=1
    if w5==2:
        max_prost=max(max_prost, m5)
    m6 = d * 10 + c
    w6 = 0
    for i6 in range(1, m6+1):
        if m6 % i6==0:
            w6+=1
    if w6==2:
        max_prost=max(max_prost, m6)
    m7 = a
    w7 = 0
    for i7 in range(1, m7+1):
        if m7 % i7==0:
            w7+=1
    if w7==2:
        max_prost=max(max_prost, m7)
    m8 = b
    w8 = 0
    for i8 in range(1, m8+1):
        if m8 % i8==0:
            w8+=1
    if w8==2:
        max_prost=max(max_prost, m8)
    m9 = d
    w9 = 0
    for i9 in range(1, m9+1):
        if m9 % i9==0:
            w9+=1
    if w9==2:
        max_prost=max(max_prost, m9)
    m10 = c
    w10 = 0
    for i10 in range(1, m10+1):
        if m10 % i10==0:
            w10+=1
    if w10==2:
        max_prost=max(max_prost, m10)
    print(max_prost)
